package LeetCode.leetcode17;

import java.util.*;

public class Review1 {
    private static final List<String> NUMS = Arrays.asList(new String[]{"", "", "abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz"});
    public List<String> letterCombinations(String digits) {
        List<String> res = new ArrayList<>();
        if (digits == null || digits.isEmpty()) return res;
        backTracking(new StringBuilder(), res, digits, 0);
        return res;
    }
    public void backTracking(StringBuilder sb,List<String> res, String digits, int startIndex) {
        if (sb.length() == digits.length()) {
            res.add(new String(sb));
            return;
        }
        if (startIndex == digits.length()) return;
        int curNum = digits.charAt(startIndex) - '0';
        String curString = NUMS.get(curNum);
        for (int i = 0; i < curString.length(); i++) {
            sb.append(curString.charAt(i));
            backTracking(sb, res, digits, startIndex + 1);
            sb.deleteCharAt(sb.length() - 1);
        }
    }
}
